public class O33 {
    public boolean verifyPostorder(int[] postorder) {
        return backStack(postorder,0,postorder.length-1);
    }
    boolean backStack(int[] postorder, int l, int r){
        if (l>=r)
            return true;
        int now = l;
        while (now <= r&&postorder[now]<postorder[r]){
            now++;
        }
        int m = now;
        while (now<r){
            now++;
            if (postorder[now]<postorder[r])
                return false;
        }
        return backStack(postorder,l,m-1)&&backStack(postorder,m,r-1);
    }
}
